/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package telas;

import controle.ControleTempo;
import tabela.Cabecalho;
import classes.Clientes;
import tabela.TabelaModelo;
import javax.swing.JScrollBar;
import javax.swing.table.TableColumn;

/**
 *
 * @author pc
 */
public class ConsultaClientes extends javax.swing.JDialog {

    Clientes cliente;
    TabelaModelo tabModelo;
    ControleTempo controle;
    
    public ConsultaClientes(java.awt.Frame parent, boolean modal, Clientes cliente, ControleTempo controle) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        this.cliente = cliente;
        this.controle = controle;
        formataTabela();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTTabela = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Eclipse Lan House");
        setResizable(false);

        jTTabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTTabela.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jTTabelaMouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jTTabela);

        jLabel1.setText("* Clique na linha do cliente para Liberar um Computador");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 663, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addGap(7, 7, 7))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTTabelaMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTTabelaMouseReleased
       linhaSelecionada();
    }//GEN-LAST:event_jTTabelaMouseReleased

    
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTTabela;
    // End of variables declaration//GEN-END:variables
    
    private void formataTabela(){
        tabModelo = new TabelaModelo(cliente.getUsuarios(),cliente.getCabecalho());//cria a matriz de acordo com o total de usuarios cadastrados.
        jTTabela.setModel(tabModelo);
        Cabecalho cabecalhoMatriz = new Cabecalho();
        TableColumn tc = jTTabela.getColumn("");
        tc.setCellRenderer(cabecalhoMatriz);
        jScrollPane1.setHorizontalScrollBar(new JScrollBar(0));
        jTTabela.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
    }
    
    private void linhaSelecionada(){
        
        Object dados = jTTabela.getValueAt(jTTabela.getSelectedRow(), 0);
        System.out.println(dados);
        if(dados != null){
            new LiberaComputador(null, true, cliente, controle, jTTabela.getSelectedRow()).setVisible(true);
        }
    }
}
